Module modXML
    Public Sub writeConfiguration()
        Dim xml As Xml.XmlTextWriter
        Dim i As Integer

        xml = New Xml.XmlTextWriter(Application.StartupPath & "\adminConfig.xml", Nothing)

        With xml
            .Indentation = 4
            .IndentChar = " "
            .Formatting = .Indentation
            .WriteStartDocument()

            .WriteStartElement("Config")
            .WriteComment("ERN Admin Version: " & commonGlobals.ernAdminVersion)
            .WriteStartElement("General")
            .WriteElementString("Server", frmMain.net.getServerName)
            .WriteEndElement() 'end GENERAL

            .WriteStartElement("Options")
            .WriteStartElement("ComputerDetails")
            .WriteElementString("Architecture", options.computerDetails.showColumns.arch)
            .WriteElementString("CheckInTime", options.computerDetails.showColumns.checkinTime)
            .WriteElementString("ComputerName", options.computerDetails.showColumns.computerName)
            .WriteElementString("CPUCount", options.computerDetails.showColumns.cpuCount)
            .WriteElementString("CPUDetails", options.computerDetails.showColumns.cpuDetails)
            .WriteElementString("HardDrives", options.computerDetails.showColumns.hardDrives)
            .WriteElementString("IP", options.computerDetails.showColumns.ip)
            .WriteElementString("LoggedInUser", options.computerDetails.showColumns.loggedinUser)
            .WriteElementString("Manufacturer", options.computerDetails.showColumns.manufacturer)
            .WriteElementString("Model", options.computerDetails.showColumns.model)
            .WriteElementString("OperatingSystem", options.computerDetails.showColumns.operatingSystem)
            .WriteElementString("ProcessCount", options.computerDetails.showColumns.processesCount)
            .WriteElementString("RAM", options.computerDetails.showColumns.ram)
            .WriteElementString("Serial", options.computerDetails.showColumns.serial)
            .WriteElementString("Status", options.computerDetails.showColumns.status)
            .WriteElementString("TempAlert", options.computerDetails.showColumns.temp)
            .WriteElementString("Uptime", options.computerDetails.showColumns.uptime)

            .WriteStartElement("Tools")
            .WriteElementString("toolCount", options.computerDetails.tools.cmd.Length - 1)
            For i = 0 To options.computerDetails.tools.cmd.Length - 1
                If options.computerDetails.tools.text(i) <> "" Then
                    .WriteElementString("text", options.computerDetails.tools.text(i))
                    .WriteElementString("cmd", options.computerDetails.tools.cmd(i))
                End If
            Next
            .WriteEndElement()
            .WriteEndElement() 'end computer details

            .WriteStartElement("Security")
            .WriteElementString("DomainAdminUser", options.security.domainAdminUser)
            .WriteElementString("DomainAdminPassword", encrypt(options.security.domainAdminPassword))
            .WriteEndElement() 'end security

            .WriteEndElement() 'end options
            .WriteEndElement() 'end Root (config)

            .WriteEndDocument()
            .Flush()
            .Close()
        End With
    End Sub

    Public Sub readConfiguration()
        Dim xml As New Xml.XmlDocument
        Dim nodeList As Xml.XmlNodeList
        Dim node As Xml.XmlNode
        Dim i As Integer

        Dim serverName As String = "localhost"
        options.computerDetails.showColumns.arch = False
        options.computerDetails.showColumns.checkinTime = True
        options.computerDetails.showColumns.computerName = True
        options.computerDetails.showColumns.cpuCount = False
        options.computerDetails.showColumns.cpuDetails = False
        options.computerDetails.showColumns.hardDrives = True
        options.computerDetails.showColumns.ip = True
        options.computerDetails.showColumns.loggedinUser = True
        options.computerDetails.showColumns.manufacturer = False
        options.computerDetails.showColumns.model = True
        options.computerDetails.showColumns.operatingSystem = True
        options.computerDetails.showColumns.processesCount = False
        options.computerDetails.showColumns.ram = True
        options.computerDetails.showColumns.serial = True
        options.computerDetails.showColumns.status = True
        options.computerDetails.showColumns.temp = False
        options.computerDetails.showColumns.uptime = True

        ReDim options.computerDetails.tools.cmd(-1)
        ReDim options.computerDetails.tools.text(-1)

        If System.IO.File.Exists(Application.StartupPath & "\adminConfig.xml") Then
            xml.Load(Application.StartupPath & "\adminConfig.xml")
            nodeList = xml.SelectNodes("/Config/General")
            For Each node In nodeList
                'get the server name
                serverName = node.ChildNodes.Item(0).InnerText
            Next

            nodeList = xml.SelectNodes("/Config/Options/ComputerDetails")
            For Each node In nodeList
                options.computerDetails.showColumns.arch = node.ChildNodes.Item(0).InnerText
                options.computerDetails.showColumns.checkinTime = node.ChildNodes.Item(1).InnerText
                options.computerDetails.showColumns.computerName = node.ChildNodes.Item(2).InnerText
                options.computerDetails.showColumns.cpuCount = node.ChildNodes.Item(3).InnerText
                options.computerDetails.showColumns.cpuDetails = node.ChildNodes.Item(4).InnerText
                options.computerDetails.showColumns.hardDrives = node.ChildNodes.Item(5).InnerText
                options.computerDetails.showColumns.ip = node.ChildNodes.Item(6).InnerText
                options.computerDetails.showColumns.loggedinUser = node.ChildNodes.Item(7).InnerText
                options.computerDetails.showColumns.manufacturer = node.ChildNodes.Item(8).InnerText
                options.computerDetails.showColumns.model = node.ChildNodes.Item(9).InnerText
                options.computerDetails.showColumns.operatingSystem = node.ChildNodes.Item(10).InnerText
                options.computerDetails.showColumns.processesCount = node.ChildNodes.Item(11).InnerText
                options.computerDetails.showColumns.ram = node.ChildNodes.Item(12).InnerText
                options.computerDetails.showColumns.serial = node.ChildNodes.Item(13).InnerText
                options.computerDetails.showColumns.status = node.ChildNodes.Item(14).InnerText
                options.computerDetails.showColumns.temp = node.ChildNodes.Item(15).InnerText
                options.computerDetails.showColumns.uptime = node.ChildNodes.Item(16).InnerText
            Next

            nodeList = xml.SelectNodes("/Config/Options/ComputerDetails/Tools")
            For Each node In nodeList
                ReDim options.computerDetails.tools.cmd(node.ChildNodes.Item(0).InnerText)
                ReDim options.computerDetails.tools.text(node.ChildNodes.Item(0).InnerText)
                For i = 0 To node.ChildNodes.Item(0).InnerText
                    If Not node.ChildNodes.Item((i * 2) + 1) Is Nothing Then options.computerDetails.tools.text(i) = node.ChildNodes.Item((i * 2) + 1).InnerText
                    If Not node.ChildNodes.Item((i * 2) + 2) Is Nothing Then options.computerDetails.tools.cmd(i) = node.ChildNodes.Item((i * 2) + 2).InnerText
                Next
            Next

            nodeList = xml.SelectNodes("/Config/Options/Security")
            For Each node In nodeList
                options.security.domainAdminUser = node.ChildNodes.Item(0).InnerText
                options.security.domainAdminPassword = decrypt(node.ChildNodes.Item(1).InnerText)
            Next
        End If

        frmMain.net.setServerName(serverName)
    End Sub

    Public Function encrypt(ByVal str As String) As String
        Return str
    End Function

    Public Function decrypt(ByVal str As String) As String
        Return str
    End Function
End Module
